/*     */ package com.zimbra.qa.unittest.prov.soap;
/*     */ 
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.SoapHttpTransport.HttpDebugListener;
/*     */ import java.io.PrintStream;
/*     */ import org.apache.commons.httpclient.Cookie;
/*     */ import org.apache.commons.httpclient.Header;
/*     */ import org.apache.commons.httpclient.HttpState;
/*     */ import org.apache.commons.httpclient.URI;
/*     */ import org.apache.commons.httpclient.URIException;
/*     */ import org.apache.commons.httpclient.methods.PostMethod;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class SoapDebugListener
/*     */   implements SoapHttpTransport.HttpDebugListener
/*     */ {
/*     */   SoapDebugListener() {}
/*     */   
/*     */   static enum Level
/*     */   {
/*  32 */     OFF, 
/*  33 */     HEADER, 
/*  34 */     BODY, 
/*  35 */     ALL;
/*     */     
/*     */     private Level() {}
/*  38 */     private static boolean needsHeader(Level level) { return (level == ALL) || (level == HEADER); }
/*     */     
/*     */     private static boolean needsBody(Level level)
/*     */     {
/*  42 */       return (level == ALL) || (level == BODY);
/*     */     }
/*     */   }
/*     */   
/*  46 */   private Level level = Level.BODY;
/*     */   
/*     */ 
/*     */ 
/*     */   SoapDebugListener(Level level)
/*     */   {
/*  52 */     this.level = level;
/*     */   }
/*     */   
/*     */   public void receiveSoapMessage(PostMethod postMethod, Element envelope)
/*     */   {
/*  57 */     if (this.level == Level.OFF) {
/*  58 */       return;
/*     */     }
/*     */     
/*  61 */     System.out.println();
/*  62 */     System.out.println("=== Response ===");
/*     */     
/*  64 */     if (Level.needsHeader(this.level)) {
/*  65 */       Header[] headers = postMethod.getResponseHeaders();
/*  66 */       for (Header header : headers) {
/*  67 */         System.out.println(header.toString().trim());
/*     */       }
/*  69 */       System.out.println();
/*     */     }
/*     */     
/*  72 */     if (Level.needsBody(this.level)) {
/*  73 */       System.out.println(envelope.prettyPrint());
/*     */     }
/*     */   }
/*     */   
/*     */   public void sendSoapMessage(PostMethod postMethod, Element envelope, HttpState httpState)
/*     */   {
/*  79 */     if (this.level == Level.OFF) {
/*  80 */       return;
/*     */     }
/*     */     
/*  83 */     System.out.println();
/*  84 */     System.out.println("=== Request ===");
/*     */     
/*  86 */     if (Level.needsHeader(this.level)) {
/*     */       try {
/*  88 */         URI uri = postMethod.getURI();
/*  89 */         System.out.println(uri.toString());
/*     */       } catch (URIException e) {
/*  91 */         e.printStackTrace();
/*     */       }
/*     */       
/*     */ 
/*  95 */       Header[] headers = postMethod.getRequestHeaders();
/*  96 */       for (Header header : headers) {
/*  97 */         System.out.println(header.toString().trim());
/*     */       }
/*  99 */       System.out.println();
/*     */       
/*     */ 
/* 102 */       if (httpState != null) {
/* 103 */         Cookie[] cookies = httpState.getCookies();
/* 104 */         for (Cookie cookie : cookies) {
/* 105 */           System.out.println("Cookie: " + cookie.toString());
/*     */         }
/*     */       }
/* 108 */       System.out.println();
/*     */     }
/*     */     
/* 111 */     if (Level.needsBody(this.level)) {
/* 112 */       System.out.println(envelope.prettyPrint());
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/soap/SoapDebugListener.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */